﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using BlogEngine.Core;
using BlogEngine.Core.Web.Controls;


[Extension("Add the SociableBE-Extension to each post.", "1.1",
  "<a href=\"http://gordon-breuer.de/page/SociableBE-Extension-for-BlogEngineNET.aspx\" target=\"_blank\">Gordon Breuer</a>")]
public class SociableBE {
  protected static ExtensionSettings _settings;

  public SociableBE() {
    Post.Serving += AddSociableBE;
    InitSettings();
  }

  private static void InitSettings() {
    var settings = new ExtensionSettings("SociableBE");

    settings.AddParameter("Imagepath");
    settings.AddParameter("Tagline");
    settings.AddParameter("Services");

    settings.AddValue("Imagepath", "/SociableBE/img/");
    settings.AddValue("Tagline", "Share or Bookmark this post&hellip;");
    settings.AddValue("Services", string.Empty);

    settings.IsScalar = true;

    ExtensionManager.SetAdminPage("SociableBE", "~/SociableBE/Admin.aspx");

    ExtensionManager.ImportSettings(settings);
    _settings = ExtensionManager.GetSettings("SociableBE");
  }

  private static void AddSociableBE(object sender, ServingEventArgs e) {
    if (e.Location == ServingLocation.Feed)
      return;

    if (HttpContext.Current != null) {
      if (HttpContext.Current.CurrentHandler is BlogBasePage)
        ((BlogBasePage)HttpContext.Current.CurrentHandler).LoadComplete += basePage_LoadComplete;
    }

    var post = (Post)sender;
    var _services = new List<string>();
    var _usedServices = new List<SociableBEEntry>();

    if (_settings == null)
      InitSettings();

    string imagePath = _settings.GetSingleValue("Imagepath");
    string tagLine = _settings.GetSingleValue("Tagline");
    _services.AddRange(_settings.GetSingleValue("Services").Split(';'));
    _services.RemoveAll(rx => rx == string.Empty);

    foreach (string s in _services) {
      SociableBEEntry _r = GetServices().Where(j => j.uid.ToString() == s).FirstOrDefault();
      _usedServices.Add(new SociableBEEntry(_r.uid, _r.name, _r.url, _r.icon, _r.css));
    }

    var sociableBEhtml = new StringBuilder();
    if (!string.IsNullOrEmpty(tagLine))
      sociableBEhtml.AppendFormat("<div class=\"sociablebe_tagline\">{0}</div>", tagLine);
    sociableBEhtml.AppendLine("<div class=\"sociablebe\"><ul>");

    foreach (SociableBEEntry i in _usedServices) {
      string _url = i.url.Replace("PERMALINK", HttpUtility.UrlEncode(post.AbsoluteLink.ToString()))
        .Replace("TITLE", HttpUtility.UrlEncode(post.Title))
        .Replace("BLOGNAME", HttpUtility.UrlEncode(BlogSettings.Instance.Name))
        .Replace("EXCERPT", HttpUtility.UrlEncode(post.Description));
      var _link = new StringBuilder("<li>");
      _link.AppendFormat("<a rel=\"nofollow\" target=\"_blank\" href=\"{0}\" title=\"{1}\">", _url, i.name);
      _link.AppendFormat("<img src=\"{0}\" title=\"{1}\" alt=\"{1}\" class=\"sociablebe-hovers{2}\" />",
                         imagePath + i.icon, i.name, i.css);
      _link.AppendLine("</a></li>");
      sociableBEhtml.AppendLine(_link.ToString());
    }

    sociableBEhtml.AppendLine("</ul></div>");

    e.Body += sociableBEhtml.ToString();
  }

  private static void basePage_LoadComplete(object sender, EventArgs e) {
    var basePage = sender as BlogBasePage;
    if (basePage == null) return;
    if (basePage.Header.FindControl("SociableBECss") != null) return;
    var SbeCss = new LiteralControl {
                                      ID = "SociableBECss",
                                      Text =
                                        "<link rel=\"stylesheet\" href=\"/SociableBE/SociableBE.css\" type=\"text/css\" />"
                                    };
    basePage.Header.Controls.Add(SbeCss);
  }

  public static List<SociableBEEntry> GetServices() {
    int i = 0;
    var _l = new List<SociableBEEntry> {
                                         new SociableBEEntry(++i, "BarraPunto",
                                                             "http://barrapunto.com/submit.pl?subj=TITLE&amp;story=PERMALINK",
                                                             "barrapunto.png"),
                                         new SociableBEEntry(++i, "blinkbits",
                                                             "http://www.blinkbits.com/bookmarklets/save.php?v=1&amp;source_url=PERMALINK&amp;title=TITLE&amp;body=TITLE",
                                                             "blinkbits.png"),
                                         new SociableBEEntry(++i, "BlinkList",
                                                             "http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Url=PERMALINK&amp;Title=TITLE",
                                                             "blinklist.png"),
                                         new SociableBEEntry(++i,
                                                             "BlogMemes FR",
                                                             "http://www.blogmemes.fr/post.php?url=PERMALINK&amp;title=TITLE",
                                                             "blogmemes.png"),
                                         new SociableBEEntry(++i,
                                                             "BlogMemes ES",
                                                             "http://www.blogmemes.com/post.php?url=PERMALINK&amp;title=TITLE",
                                                             "blogmemes.png"),
                                         new SociableBEEntry(++i,
                                                             "BlogMemes CN",
                                                             "http://www.blogmemes.cn/post.php?url=PERMALINK&amp;title=TITLE",
                                                             "blogmemes.png"),
                                         new SociableBEEntry(++i,
                                                             "BlogMemes JP",
                                                             "http://www.blogmemes.jp/post.php?url=PERMALINK&amp;title=TITLE",
                                                             "blogmemes.png"),
                                         new SociableBEEntry(++i, "blogmarks",
                                                             "http://blogmarks.net/my/new.php?mini=1&amp;simple=1&amp;url=PERMALINK&amp;title=TITLE",
                                                             "blogmarks.png"),
                                         new SociableBEEntry(++i, "Blogosphere News",
                                                             "http://www.blogospherenews.com/submit.php?url=PERMALINK&amp;title=TITLE",
                                                             "blogospherenews.gif"),
                                         new SociableBEEntry(++i, "Blogsvine",
                                                             "http://blogsvine.com/submit.php?url=PERMALINK",
                                                             "blogsvine.png"),
                                         new SociableBEEntry(++i, "blogtercimlap",
                                                             "http://cimlap.blogter.hu/index.php?action=suggest_link&amp;title=TITLE&amp;url=PERMALINK",
                                                             "blogter.png"),
                                         new SociableBEEntry(++i, "Faves",
                                                             "http://faves.com/Authoring.aspx?u=PERMALINK&amp;title=TITLE",
                                                             "bluedot.png"),
                                         new SociableBEEntry(++i, "Book.mark.hu",
                                                             "http://book.mark.hu/bookmarks.php/?action=add&amp;address=PERMALINK%2F&amp;title=TITLE",
                                                             "bookmarkhu.png"),
                                         new SociableBEEntry(++i, "Bumpzee",
                                                             "http://www.bumpzee.com/bump.php?u=PERMALINK",
                                                             "bumpzee.png"),
                                         new SociableBEEntry(++i, "co.mments",
                                                             "http://co.mments.com/track?url=PERMALINK&amp;title=TITLE",
                                                             "co.mments.gif"),
                                         new SociableBEEntry(++i, "connotea",
                                                             "http://www.connotea.org/addpopup?continue=confirm&amp;uri=PERMALINK&amp;title=TITLE",
                                                             "connotea.png"),
                                         new SociableBEEntry(++i, "del.icio.us",
                                                             "http://del.icio.us/post?url=PERMALINK&amp;title=TITLE",
                                                             "delicious.png"),
                                         new SociableBEEntry(++i, "De.lirio.us",
                                                             "http://de.lirio.us/rubric/post?uri=PERMALINK;title=TITLE;when_done=go_back",
                                                             "delirious.png"),
                                         new SociableBEEntry(++i, "Design Float",
                                                             "http://www.designfloat.com/submit.php?url=PERMALINK&amp;title=TITLE",
                                                             "designfloat.gif"),
                                         new SociableBEEntry(++i, "Digg",
                                                             "http://digg.com/submit?phase=2&amp;url=PERMALINK&amp;title=TITLE",
                                                             "digg.png"),
                                         new SociableBEEntry(++i, "DotNetKicks",
                                                             "http://www.dotnetkicks.com/kick/?url=PERMALINK&amp;title=TITLE",
                                                             "dotnetkicks.png"),
                                         new SociableBEEntry(++i, "DZone",
                                                             "http://www.dzone.com/links/add.html?url=PERMALINK&amp;title=TITLE",
                                                             "dzone.png"),
                                         new SociableBEEntry(++i, "eKudos",
                                                             "http://www.ekudos.nl/artikel/nieuw?url=PERMALINK&amp;title=TITLE",
                                                             "ekudos.gif"),
                                         new SociableBEEntry(++i, "E-Mail", "mailto:?subject=TITLE&amp;body=PERMALINK",
                                                             "email_link.png"),
                                         new SociableBEEntry(++i, "Facebook",
                                                             "http://www.facebook.com/share.php?u=PERMALINK&amp;t=TITLE",
                                                             "facebook.png"),
                                         new SociableBEEntry(++i, "Fark",
                                                             "http://cgi.fark.com/cgi/fark/farkit.pl?h=TITLE&amp;u=PERMALINK",
                                                             "fark.png"),
                                         new SociableBEEntry(++i, "feedmelinks",
                                                             "http://feedmelinks.com/categorize?from=toolbar&amp;op=submit&amp;url=PERMALINK&amp;name=TITLE",
                                                             "feedmelinks.png"),
                                         new SociableBEEntry(++i, "Furl",
                                                             "http://www.furl.net/storeIt.jsp?u=PERMALINK&amp;t=TITLE",
                                                             "furl.png"),
                                         new SociableBEEntry(++i, "Fleck",
                                                             "http://extension.fleck.com/?v=b.0.804&amp;url=PERMALINK",
                                                             "fleck.gif"),
                                         new SociableBEEntry(++i, "GeenRedactie",
                                                             "http://www.geenredactie.nl/submit?url=PERMALINK&amp;title=TITLE",
                                                             "geenredactie.png"),
                                         new SociableBEEntry(++i, "Global Grind",
                                                             "http://globalgrind.com/submission/submit.aspx?url=PERMALINK&amp;type=Article&amp;title=TITLE",
                                                             "globalgrind.gif"),
                                         new SociableBEEntry(++i, "Google",
                                                             "http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=PERMALINK&amp;title=TITLE",
                                                             "googlebookmark.png"),
                                         new SociableBEEntry(++i, "Gwar",
                                                             "http://www.gwar.pl/DodajGwar.html?u=PERMALINK",
                                                             "gwar.gif"),
                                         new SociableBEEntry(++i, "Haohao",
                                                             "http://www.haohaoreport.com/submit.php?url=PERMALINK&amp;title=TITLE",
                                                             "haohao.png"),
                                         new SociableBEEntry(++i, "HealthRanker",
                                                             "http://healthranker.com/submit.php?url=PERMALINK&amp;title=TITLE",
                                                             "healthranker.gif"),
                                         new SociableBEEntry(++i, "Hemidemi",
                                                             "http://www.hemidemi.com/user_bookmark/new?title=TITLE&amp;url=PERMALINK",
                                                             "hemidemi.png"),
                                         new SociableBEEntry(++i, "IndianPad",
                                                             "http://www.indianpad.com/submit.php?url=PERMALINK",
                                                             "indianpad.png"),
                                         new SociableBEEntry(++i, "Internetmedia",
                                                             "http://internetmedia.hu/submit.php?url=PERMALINK",
                                                             "im.png"),
                                         new SociableBEEntry(++i, "kick.ie",
                                                             "http://kick.ie/submit/?url=PERMALINK&amp;title=TITLE",
                                                             "kickit.png"),
                                         new SociableBEEntry(++i, "Kirtsy",
                                                             "http://www.kirtsy.com/submit.php?url=PERMALINK&amp;title=TITLE",
                                                             "kirtsy.gif"),
                                         new SociableBEEntry(++i, "laaik.it",
                                                             "http://laaik.it/NewStoryCompact.aspx?uri=PERMALINK&amp;headline=TITLE&amp;cat=5e082fcc-8a3b-47e2-acec-fdf64ff19d12",
                                                             "laaikit.png"),
                                         new SociableBEEntry(++i, "Leonaut",
                                                             "http://www.leonaut.com/submit.php?url=PERMALINK&amp;title=TITLE",
                                                             "leonaut.gif"),
                                         new SociableBEEntry(++i, "LinkArena",
                                                             "http://linkarena.com/bookmarks/addlink/?url=PERMALINK&amp;title=TITLE",
                                                             "linkarena.gif"),
                                         new SociableBEEntry(++i, "LinkaGoGo",
                                                             "http://www.linkagogo.com/go/AddNoPopup?url=PERMALINK&amp;title=TITLE",
                                                             "linkagogo.png"),
                                         new SociableBEEntry(++i, "LinkedIn",
                                                             "http://www.linkedin.com/shareArticle?mini=true&amp;url=PERMALINK&amp;title=TITLE&amp;source=BLOGNAME&amp;summary=EXCERPT",
                                                             "linkedin.png"),
                                         new SociableBEEntry(++i, "Linkter",
                                                             "http://www.linkter.hu/index.php?action=suggest_link&amp;url=PERMALINK&amp;title=TITLE",
                                                             "linkter.png"),
                                         new SociableBEEntry(++i, "Live",
                                                             "https://favorites.live.com/quickadd.aspx?marklet=1&amp;url=PERMALINK&amp;title=TITLE",
                                                             "live.png"),
                                         new SociableBEEntry(++i, "Ma.gnolia",
                                                             "http://ma.gnolia.com/bookmarklet/add?url=PERMALINK&amp;title=TITLE",
                                                             "magnolia.png"),
                                         new SociableBEEntry(++i, "Meneame",
                                                             "http://meneame.net/submit.php?url=PERMALINK",
                                                             "meneame.gif"),
                                         new SociableBEEntry(++i, "MisterWong",
                                                             "http://www.mister-wong.com/addurl/?bm_url=PERMALINK&amp;bm_description=TITLE&amp;plugin=soc",
                                                             "misterwong.gif"),
                                         new SociableBEEntry(++i, "MisterWong.DE",
                                                             "http://www.mister-wong.de/addurl/?bm_url=PERMALINK&amp;bm_description=TITLE&amp;plugin=soc",
                                                             "misterwong.gif"),
                                         new SociableBEEntry(++i, "Mixx",
                                                             "http://www.mixx.com/submit?page_url=PERMALINK&amp;title=TITLE",
                                                             "mixx.png"),
                                         new SociableBEEntry(++i, "msdn Social",
                                                             "http://social.msdn.microsoft.com/bookmarks/de-de/action/Create/s/E/?url=PERMALINK&amp;ttl=TITLE",
                                                             "msdn.png"),
                                         new SociableBEEntry(++i, "muti",
                                                             "http://www.muti.co.za/submit?url=PERMALINK&amp;title=TITLE",
                                                             "muti.png"),
                                         new SociableBEEntry(++i, "MyShare",
                                                             "http://myshare.url.com.tw/index.php?func=newurl&amp;url=PERMALINK&amp;desc=TITLE",
                                                             "myshare.png"),
                                         new SociableBEEntry(++i, "MySpace",
                                                             "http://www.myspace.com/Modules/PostTo/Pages/?u=PERMALINK&amp;t=TITLE",
                                                             "myspace.png"),
                                         new SociableBEEntry(++i, "N4G",
                                                             "http://www.n4g.com/tips.aspx?url=PERMALINK&amp;title=TITLE",
                                                             "n4g.gif"),
                                         new SociableBEEntry(++i, "NewsVine",
                                                             "http://www.newsvine.com/_tools/seed&amp;save?u=PERMALINK&amp;h=TITLE",
                                                             "newsvine.png"),
                                         new SociableBEEntry(++i, "Netvouz",
                                                             "http://www.netvouz.com/action/submitBookmark?url=PERMALINK&amp;title=TITLE&amp;popup=no",
                                                             "netvouz.png"),
                                         new SociableBEEntry(++i, "NuJIJ",
                                                             "http://nujij.nl/jij.lynkx?t=TITLE&amp;u=PERMALINK",
                                                             "nujij.gif"),
                                         new SociableBEEntry(++i, "Ping.fm",
                                                             "http://ping.fm/ref/?link=PERMALINK&amp;title=TITLE",
                                                             "ping.gif"),
                                         new SociableBEEntry(++i, "PlugIM",
                                                             "http://www.plugim.com/submit?url=PERMALINK&amp;title=TITLE",
                                                             "plugim.png"),
                                         new SociableBEEntry(++i, "Pownce",
                                                             "http://pownce.com/send/link/?url=PERMALINK&amp;note_body=TITLE&amp;note_to=all",
                                                             "pownce.gif"),
                                         new SociableBEEntry(++i, "ppnow",
                                                             "http://www.ppnow.net/submit.php?url=PERMALINK",
                                                             "ppnow.png"),
                                         new SociableBEEntry(++i, "Print", "javascript:window.print();", "printer.png"),
                                         new SociableBEEntry(++i, "Propeller",
                                                             "http://www.propeller.com/submit/?url=PERMALINK",
                                                             "propeller.gif"),
                                         new SociableBEEntry(++i, "Ratimarks",
                                                             "http://ratimarks.org/bookmarks.php/?action=add&address=PERMALINK&amp;title=TITLE",
                                                             "ratimarks.png"),
                                         new SociableBEEntry(++i, "Rec6",
                                                             "http://www.syxt.com.br/rec6/link.php?url=PERMALINK&amp;=TITLE",
                                                             "rec6.gif"),
                                         new SociableBEEntry(++i, "Reddit",
                                                             "http://reddit.com/submit?url=PERMALINK&amp;title=TITLE",
                                                             "reddit.png"),
                                         new SociableBEEntry(++i, "SalesMarks",
                                                             "http://salesmarks.com/submit?edit[url]=PERMALINK&amp;edit[title]=TITLE",
                                                             "salesmarks.gif"),
                                         new SociableBEEntry(++i, "Scoopeo",
                                                             "http://www.scoopeo.com/scoop/new?newurl=PERMALINK&amp;title=TITLE",
                                                             "scoopeo.png"),
                                         new SociableBEEntry(++i, "scuttle",
                                                             "http://www.scuttle.org/bookmarks.php/maxpower?action=add&amp;address=PERMALINK&amp;title=TITLE",
                                                             "scuttle.png"),
                                         new SociableBEEntry(++i, "Segnalo",
                                                             "http://segnalo.alice.it/post.html.php?url=PERMALINK&amp;title=TITLE",
                                                             "segnalo.gif"),
                                         new SociableBEEntry(++i, "Shadows",
                                                             "http://www.shadows.com/features/tcr.htm?url=PERMALINK&amp;title=TITLE",
                                                             "shadows.png"),
                                         new SociableBEEntry(++i, "Simpy",
                                                             "http://www.simpy.com/simpy/LinkAdd.do?href=PERMALINK&amp;title=TITLE",
                                                             "simpy.png"),
                                         new SociableBEEntry(++i, "Slashdot",
                                                             "http://slashdot.org/bookmark.pl?title=TITLE&amp;url=PERMALINK",
                                                             "slashdot.png"),
                                         new SociableBEEntry(++i, "Smarking",
                                                             "http://smarking.com/editbookmark/?url=PERMALINK&amp;title=TITLE",
                                                             "smarking.png"),
                                         new SociableBEEntry(++i, "Socialogs",
                                                             "http://socialogs.com/add_story.php?story_url=PERMALINK&amp;story_title=TITLE",
                                                             "socialogs.gif"),
                                         new SociableBEEntry(++i, "Spurl",
                                                             "http://www.spurl.net/spurl.php?url=PERMALINK&amp;title=TITLE",
                                                             "spurl.png"),
                                         new SociableBEEntry(++i, "SphereIt",
                                                             "http://www.sphere.com/search?q=sphereit:PERMALINK&amp;title=TITLE",
                                                             "sphere.png"),
                                         new SociableBEEntry(++i, "Sphinn",
                                                             "http://sphinn.com/submit.php?url=PERMALINK&amp;title=TITLE",
                                                             "sphinn.gif"),
                                         new SociableBEEntry(++i, "StumbleUpon",
                                                             "http://www.stumbleupon.com/submit?url=PERMALINK&amp;title=TITLE",
                                                             "stumbleupon.png"),
                                         new SociableBEEntry(++i, "Symbaloo",
                                                             "http://www.symbaloo.com/nl/add/url=PERMALINK&amp;title=TITLE&amp;icon=http%3A//static01.symbaloo.com/_img/favicon.png",
                                                             "symbaloo.png"),
                                         new SociableBEEntry(++i, "Taggly",
                                                             "http://taggly.com/bookmarks.php/pass?action=add&amp;address=",
                                                             "taggly.png"),
                                         new SociableBEEntry(++i, "Technorati",
                                                             "http://technorati.com/faves?add=PERMALINK",
                                                             "technorati.png"),
                                         new SociableBEEntry(++i, "TailRank",
                                                             "http://tailrank.com/share/?text=&amp;link_href=PERMALINK&amp;title=TITLE",
                                                             "tailrank.png"),
                                         new SociableBEEntry(++i, "ThisNext",
                                                             "http://www.thisnext.com/pick/new/submit/sociable/?url=PERMALINK&amp;name=TITLE",
                                                             "thisnext.png"),
                                         new SociableBEEntry(++i, "Tipd", "http://tipd.com/submit.php?url=PERMALINK",
                                                             "tipd.png"),
                                         new SociableBEEntry(++i, "Tumblr",
                                                             "http://www.tumblr.com/share?v=3&amp;u=PERMALINK&amp;t=TITLE&amp;s=",
                                                             "tumblr.gif"),
                                         new SociableBEEntry(++i, "TwitThis", "http://twitter.com/home?status=PERMALINK",
                                                             "twitter.gif"),
                                         new SociableBEEntry(++i, "Upnews",
                                                             "http://www.upnews.it/submit?url=PERMALINK&amp;title=TITLE",
                                                             "upnews.gif"),
                                         new SociableBEEntry(++i, "Webnews.de",
                                                             "http://www.webnews.de/einstellen?url=PERMALINK&amp;title=TITLE",
                                                             "webnews.gif"),
                                         new SociableBEEntry(++i, "Webride",
                                                             "http://webride.org/discuss/split.php?uri=PERMALINK&amp;title=TITLE",
                                                             "webride.png"),
                                         new SociableBEEntry(++i, "Wikio", "http://www.wikio.com/vote?url=PERMALINK",
                                                             "wikio.gif"),
                                         new SociableBEEntry(++i, "Wikio FR", "http://www.wikio.fr/vote?url=PERMALINK",
                                                             "wikio.gif"),
                                         new SociableBEEntry(++i, "Wikio IT", "http://www.wikio.it/vote?url=PERMALINK",
                                                             "wikio.gif"),
                                         new SociableBEEntry(++i, "Wists",
                                                             "http://wists.com/s.php?c=&amp;r=PERMALINK&amp;title=TITLE",
                                                             "wists.png", "wists"),
                                         new SociableBEEntry(++i, "Wykop", "http://www.wykop.pl/dodaj?url=PERMALINK",
                                                             "wykop.gif"),
                                         new SociableBEEntry(++i, "Xerpi",
                                                             "http://www.xerpi.com/block/add_link_from_extension?url=PERMALINK&amp;title=TITLE",
                                                             "xerpi.gif"),
                                         new SociableBEEntry(++i, "Yahoo! Buzz",
                                                             "http://buzz.yahoo.com/submit/?submitUrl=PERMALINK&amp;submitHeadline=TITLE&amp;submitSummary=EXCERPT&amp;submitCategory=science&amp;submitAssetType=text",
                                                             "yahoobuzz.gif"),
                                         new SociableBEEntry(++i, "Yahoo! MyWeb",
                                                             "http://myweb2.search.yahoo.com/myresults/bookmarklet?u=PERMALINK&amp;=TITLE",
                                                             "yahoomyweb.png"),
                                         new SociableBEEntry(++i, "Yigg",
                                                             "http://yigg.de/neu?exturl=PERMALINK&amp;exttitle=TITLE",
                                                             "yiggit.png"),
                                         new SociableBEEntry(++i, "DotNetKicks German",
                                                             "http://dotnet-kicks.de/kick/?url=PERMALINK&amp;title=TITLE",
                                                             "dnkde.png"),
                                       };

    _l.Sort();
    return _l;
  }
}


public struct SociableBEEntry : IComparable {
  public SociableBEEntry(int _uid, string _u, string _i) : this(_uid, _i.Remove(_i.IndexOf(".")), _u, _i) {
  }

  public SociableBEEntry(int _uid, string _n, string _u, string _i)
    : this(_uid, _n, _u, _i, string.Empty) {
  }

  public SociableBEEntry(int _uid, string _n, string _u, string _i, string _c)
    : this() {
    url = _u;
    icon = _i;
    css = _c ?? string.Empty;
    name = String.IsNullOrEmpty(_n) ? _i.Remove(_i.IndexOf(".")) : _n;
    uid = _uid;
  }

  public string name { get; set; }
  public string url { get; set; }
  public string icon { get; set; }
  public string css { get; set; }
  public int uid { get; set; }

  #region IComparable Members
  public int CompareTo(object obj) {
    return name.CompareTo(obj.ToString());
  }
  #endregion

  public override string ToString() {
    return name;
  }
}